package com.dy.web.controller.system;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dy.common.utils.DateUtils;
import com.dy.system.domain.FreshWarningMsgType;
import com.dy.system.domain.InspectionReport;
import com.dy.system.service.IFreshWarningMsgTypeService;
import com.dy.system.service.IInspectionReportService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dy.common.annotation.Log;
import com.dy.common.core.controller.BaseController;
import com.dy.common.core.domain.AjaxResult;
import com.dy.common.enums.BusinessType;

import com.dy.common.utils.poi.ExcelUtil;
import com.dy.common.core.page.TableDataInfo;

/**
 * 告警消息类型Controller
 *
 * @author ruoyi
 * @date 2022-09-15
 */
@RestController
@RequestMapping("/system/warning/type")
public class FreshWarningMsgTypeController extends BaseController {
    @Autowired
    private IFreshWarningMsgTypeService freshWarningMsgTypeService;
    @Autowired
    private IInspectionReportService inspectionReportService;

    /**
     * 查询告警消息类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:list')")
    @GetMapping("/list")
    public TableDataInfo list(FreshWarningMsgType freshWarningMsgType) {
        startPage();
        List<FreshWarningMsgType> list = freshWarningMsgTypeService.selectFreshWarningMsgTypeList(freshWarningMsgType);
        return getDataTable(list);
    }

    /***
     * 查询告警类型信息
     * @param msgType
     * @return
     */
    @GetMapping("/list/data")
    public AjaxResult getWarningTypeList(FreshWarningMsgType msgType){
        List<FreshWarningMsgType> list = freshWarningMsgTypeService.selectFreshWarningMsgTypeList(msgType);
        list.forEach(m ->{
            m.setWarningLevel(1);
        });
        return AjaxResult.success(list);
    }

    /**
     * 导出告警消息类型列表
     */
    @PreAuthorize("@ss.hasPermi('system:type:export')")
    @Log(title = "告警消息类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FreshWarningMsgType freshWarningMsgType) {
        List<FreshWarningMsgType> list = freshWarningMsgTypeService.selectFreshWarningMsgTypeList(freshWarningMsgType);
        ExcelUtil<FreshWarningMsgType> util = new ExcelUtil<FreshWarningMsgType>(FreshWarningMsgType.class);
        util.exportExcel(response, list, "告警消息类型数据");
    }

    /**
     * 获取告警消息类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:type:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(freshWarningMsgTypeService.selectFreshWarningMsgTypeById(id));
    }

    /**
     * 新增告警消息类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:add')")
    @Log(title = "告警消息类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FreshWarningMsgType freshWarningMsgType) {
        return toAjax(freshWarningMsgTypeService.insertFreshWarningMsgType(freshWarningMsgType));
    }

    /**
     * 修改告警消息类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:edit')")
    @Log(title = "告警消息类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FreshWarningMsgType freshWarningMsgType){
        return toAjax(freshWarningMsgTypeService.updateFreshWarningMsgType(freshWarningMsgType));
    }

    /**
     * 删除告警消息类型
     */
    @PreAuthorize("@ss.hasPermi('system:type:remove')")
    @Log(title = "告警消息类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(freshWarningMsgTypeService.deleteFreshWarningMsgTypeByIds(ids));
    }
}
